package com.NetSunWeiQin.chapter03;

import java.io.*;
import java.net.*;
public class Server {
  private int port=8000;
  private ServerSocket serverSocket;

  public Server() throws IOException {
    int backlog = 3;
    serverSocket = new ServerSocket(port,backlog);  //设置请求队列是3个
    System.out.println("server started.....  has "+ backlog+ " 个请求队列..... " );
  }

  public void service() {
    while (true) {
      Socket socket=null;
      try {
        socket = serverSocket.accept();
        System.out.println("New connection accepted " +
        socket.getInetAddress() + ":" +socket.getPort());
      }catch (IOException e) {
         e.printStackTrace();
      }finally {
         try{
           if(socket!=null)socket.close();
         }catch (IOException e) {e.printStackTrace();}
      }
    }
  }

  public static void main(String args[])throws Exception {
    Server server=new Server();
    Thread.sleep(6000*10);
    server.service();
  }
}

